
package com.drp.controller;


import com.drp.bean.Goods;
import com.drp.bean.Kind;
import com.drp.bean.Supplier;
import com.drp.bean.User;
import com.drp.service.IGoodsService;
import com.drp.service.impl.GoodsServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ren
 * @since 2022-03-16
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private IGoodsService goodsService;
    @RequestMapping("/add")
    @ResponseBody
    public void add(Goods goods, User user, Kind kind, Supplier supplier){
        boolean add = goodsService.add(goods, user, kind, supplier);
        System.out.println("add = " + add);
    }
    @RequestMapping("/get")
    @ResponseBody
    public List<Goods> getAll(){
        List<Goods> goods = goodsService.getAll();
        System.out.println("goods = " + goods);
        return goods;
    }

    @RequestMapping("/del")
    @ResponseBody
    public void delById(String goodId){
        goodsService.deleteById(Integer.parseInt(goodId));
    }
    @RequestMapping("/addGoods")
    @ResponseBody
    public void addGoods(String goodId, Goods data){

        goodsService.deleteById(Integer.parseInt(goodId));
        goodsService.addGood(data);


    }
}
